package cn.shutdown.demo.jvm.permtest;

import java.util.HashMap;
import java.util.Map;

/**
 * 测试方法区/永久区，
 * 用1.7的jdk运行加以下参数
 * -XX:PermSize=5m -XX:+PrintGCDetails -XX:MaxPermSize=5m
 * 1.8的jdk运行加以下参数
 * -XX:MaxMetaspaceSize=5m
 *
 * @author domino
 * @date 2021/5/20
 */
public class PermTest {

    public static void main(String[] args) {
        int i = 0;
        try {
            Map<String, Object> map = new HashMap<>();
            map.put("id", Integer.class);
            map.put("name", String.class);
            for (i = 0; i < 2000000000; i++) {
                CglibBean bean = new CglibBean("cn.shutdown.demo.Permtest" + i, map);
                System.out.println("created count is " + i);
            }
        } catch (Throwable e) {
            System.out.println("total create count" + i);
        } finally {
            System.out.println("total create count" + i);
        }
    }
}
